/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cannes.dao.implement;

import cannes.bean.planning.Jure;
import cannes.connexion.ConnexionBDD;
import cannes.dao.DAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author p1000666
 */
public class JureDAO extends DAO<Jure> {

    public JureDAO(Connection conn) {
        super(conn);
    }

    @Override
    public boolean create(Jure obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean update(Jure obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean delete(Jure obj) {
        try {
            ResultSet result = this.connect.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY).executeQuery(
                    "DELETE FROM jure WHERE jureid = " + obj.getId());
            result.rowDeleted();

        } catch (SQLException e) {
            e.printStackTrace();
        }

        return false;
    }

    @Override
    public int next() {
        throw new UnsupportedOperationException("Not supported yet.");
    }



    @Override
    public Jure find(int id) {
        Jure jure = new Jure();

        try {
            ResultSet result = this.connect.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY).executeQuery(
                    "SELECT * FROM jure JOIN personne ON personne.personneid = jure.jureid"
                    + " WHERE jureid = "+id
                    );
            if (result.first()) {
                jure = new Jure(result.getInt("jureid"), result.getInt("juryid"), result.getString("statut"),
                        result.getString("profession"), result.getString("nom"), result.getString("prenom"),
                        result.getString("photo"), result.getString("nationalite"));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return jure;

    }

    @Override
    public ArrayList<Jure> findAll() {
        ArrayList<Jure> listeJure = new ArrayList<Jure>();
        
        try {
            ResultSet result = this.connect.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY).executeQuery(
                    "SELECT * FROM jure JOIN personne ON personne.personneid = jure.jureid");
            while(result.next()){
                listeJure.add(new Jure(result.getInt("jureid"), result.getInt("juryid"), result.getString("statut"),
                        result.getString("profession"), result.getString("nom"), result.getString("prenom"),
                        result.getString("photo"), result.getString("nationalite")));
            }

        } catch (SQLException e) {
            //System.out.println("SQL exception: "+ e.getMessage());
            e.printStackTrace();
        }
        
        return listeJure;
    }
}
